# 拉勾取消收藏夹里失效的职位

from selenium import webdriver


def delete_link():
    lis = driver.find_elements_by_xpath('//form[@id="collectionsForm"]/ul/li')
    for li in lis:
        print(li.text)
        print(type(li.text))
        print('-' * 99)
        if '已下线' in li.text or '已删除' in li.text:
            li.find_element_by_xpath('./div/a').click()


def work():
    driver.get(url)
    print(driver.title)
    driver.find_element_by_xpath('//input[@type="text"]').send_keys('17788119925')
    driver.find_element_by_xpath('//input[@type="password"]').send_keys('4444rrrr')
    driver.find_element_by_xpath('//input[@type="submit"]').click()
    cookies = driver.get_cookies()
    print(driver.title)
    while 1:
        ym = driver.find_element_by_xpath('//span[@class="current"]').text
        if ym == '1':
            break
        delete_link()
        driver.find_element_by_xpath('//div/a[contains(text(),"上一页")]').click()


driver = webdriver.Chrome()
driver.implicitly_wait(30)
url = 'https://www.lagou.com/mycenter/collections.html?pageNo=5'
# TODO:自动点击收藏夹和最后一页
try:
    work()
except Exception as e:
    print(e)
finally:
    driver.quit()
